package com.company.koashi;

/**
 * @Author: luosiyu
 * @Description: 练习
 * @Version: 1.0
 */
public class demo {
    public static void main(String[] args) {
        System.out.println(new Rect2(2,2));
        System.out.println(new Circle2(4));
        System.out.println(new Triangle2(2,3,4));
    }
}

interface shape2{
    double areg2();
    double lengh2();
}

class Rect2 implements shape2{
    double a;
    double b;

    public Rect2() {
    }

    public Rect2(double a, double b) {
        this.a = a;
        this.b = b;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    @Override
    public double areg2() {
        return a*b;
    }

    @Override
    public double lengh2() {
        return (a+b)*2;
    }

    @Override
    public String toString() {
        return "面积"+areg2()+"周长"+lengh2();
    }
}

class Circle2 implements shape2{
    private double a;

    public Circle2() {
    }

    public Circle2(double a) {
        this.a = a;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    @Override
    public double areg2() {
        double b = Math.PI*a*a;
        return Double.valueOf(String.format("%.2f",b));
    }

    @Override
    public double lengh2() {
        double b = 2*Math.PI*a;
        return Double.valueOf(String.format("%.2f",b));
    }

    @Override
    public String toString() {
        return "面积"+areg2()+"周长"+lengh2();
    }
}

class Triangle2 implements shape2{
    private double a;
    private double b;
    private double c;
    public Triangle2() {
    }

    public Triangle2(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }

    private boolean getTeiangleTeue2(){
        return a+b>c && a+c>b && b+c>a;
    }

    @Override
    public double areg2() {
        if (getTeiangleTeue2()){
            double d = (a+b+c)/2;
            double e = Math.sqrt(d*(d-a)*(d-b)*(d-c));
            return Double.valueOf(String.format("%.2f",e));
        }
        return -1;
    }

    @Override
    public double lengh2() {
        return getTeiangleTeue2()?a+b+c:-1;
    }
    @Override
    public String toString() {
        return "面积"+areg2()+"周长"+lengh2();
    }
}
